<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI知识库</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', sans-serif;
            background-color: #f4f7f6;
            color: #333;
            display: flex;
            flex-direction: column;
            min-height: 100vh;
        }

        .page-header {
            background-color: #2c3e50;
            color: white;
            padding: 15px 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }

        .page-header .title-container {
            display: flex;
            align-items: center;
        }

        .page-header .back-btn {
            color: white;
            text-decoration: none;
            font-size: 24px;
            margin-right: 15px;
        }

        .page-header .page-title {
            font-size: 20px;
            font-weight: bold;
        }
        
        .user-info {
            display: flex;
            align-items: center;
        }

        .user-avatar {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background: #3498db;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            margin-right: 10px;
            font-size: 16px;
        }

        .user-name {
            font-weight: bold;
            font-size: 14px;
        }

        .main-container {
            flex: 1;
            padding: 30px;
            max-width: 1200px;
            margin: 0 auto;
            width: 100%;
        }

        .section {
            background-color: white;
            padding: 25px;
            border-radius: 8px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
            margin-bottom: 30px;
        }

        .section-title {
            font-size: 18px;
            font-weight: bold;
            color: #2c3e50;
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #eee;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-label {
            display: block;
            font-size: 14px;
            color: #555;
            margin-bottom: 8px;
        }

        .form-select,
        .form-input-file {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
            background-color: #fff;
        }
        
        .form-input-file {
             padding: 7px 10px; /* Adjust padding for file input */
        }

        .btn {
            padding: 10px 18px;
            border: none;
            border-radius: 4px;
            font-size: 14px;
            cursor: pointer;
            transition: background-color 0.3s ease;
            text-decoration: none;
            display: inline-block;
            text-align: center;
        }

        .btn-primary {
            background-color: #3498db;
            color: white;
        }

        .btn-primary:hover {
            background-color: #2980b9;
        }
        
        .btn-danger {
            background-color: #e74c3c;
            color: white;
        }
        .btn-danger:hover {
            background-color: #c0392b;
        }

        .btn-secondary {
            background-color: #7f8c8d;
            color: white;
        }
        .btn-secondary:hover {
            background-color: #6c7a7d;
        }

        .knowledge-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        .knowledge-table th,
        .knowledge-table td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #eee;
            font-size: 14px;
        }

        .knowledge-table th {
            background-color: #f8f9fa;
            font-weight: bold;
            color: #333;
        }

        .knowledge-table tr:hover {
            background-color: #f1f1f1;
        }
        
        .knowledge-table .action-buttons .btn {
            margin-right: 8px;
            padding: 6px 10px;
            font-size: 13px;
        }
        .knowledge-table .action-buttons .btn:last-child {
            margin-right: 0;
        }

    </style>
</head>
<body>
    <header class="page-header">
        <div class="title-container">
            <a href="AI文书首页.html" class="back-btn" title="返回首页">←</a>
            <h1 class="page-title">AI知识库管理</h1>
        </div>
        <div class="user-info">
            <div class="user-avatar">A</div>
            <div class="user-name">管理员</div>
        </div>
    </header>

    <main class="main-container">
        <!-- 添加文件区域 -->
        <section class="section">
            <h2 class="section-title">添加知识库文档</h2>
            <form id="addKnowledgeForm">
                <div class="form-group">
                    <label for="caseTypeSelect" class="form-label">选择案件类型</label>
                    <select id="caseTypeSelect" name="caseType" class="form-select" required>
                        <option value="">请选择案件类型</option>
                        <option value="临床鉴定">临床鉴定</option>
                        <option value="死亡鉴定">死亡鉴定</option>
                        <option value="医疗损害">医疗损害</option>
                        <!-- 更多案件类型可以动态加载或在此处添加 -->
                    </select>
                </div>
                <div class="form-group">
                    <label for="documentUpload" class="form-label">上传文档</label>
                    <input type="file" id="documentUpload" name="document" class="form-input-file" required>
                </div>
                <button type="submit" class="btn btn-primary">确认添加</button>
            </form>
        </section>

        <!-- 知识库列表区域 -->
        <section class="section">
            <h2 class="section-title">知识库文档列表</h2>
            <table class="knowledge-table">
                <thead>
                    <tr>
                        <th style="width: 60px;">序号</th>
                        <th style="width: 200px;">案件类型</th>
                        <th>文档名称</th>
                        <th style="width: 180px;">操作</th>
                    </tr>
                </thead>
                <tbody id="knowledgeTableBody">
                    <!-- 示例数据，实际应用中应由JavaScript动态生成 -->
                    <tr>
                        <td>1</td>
                        <td>临床鉴定</td>
                        <td>临床鉴定标准V1.2.pdf</td>
                        <td class="action-buttons">
                            <button class="btn btn-secondary btn-sm">下载</button>
                            <button class="btn btn-danger btn-sm">删除</button>
                        </td>
                    </tr>
                    <tr>
                        <td>2</td>
                        <td>死亡鉴定</td>
                        <td>死亡原因分析指南2023.docx</td>
                        <td class="action-buttons">
                            <button class="btn btn-secondary btn-sm">下载</button>
                            <button class="btn btn-danger btn-sm">删除</button>
                        </td>
                    </tr>
                    <tr>
                        <td>3</td>
                        <td>医疗损害</td>
                        <td>医疗损害责任认定细则.pptx</td>
                        <td class="action-buttons">
                            <button class="btn btn-secondary btn-sm">下载</button>
                            <button class="btn btn-danger btn-sm">删除</button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </section>
    </main>

    <script>
        // 简单的表单提交处理示例
        const addKnowledgeForm = document.getElementById('addKnowledgeForm');
        if (addKnowledgeForm) {
            addKnowledgeForm.addEventListener('submit', function(event) {
                event.preventDefault(); // 阻止表单默认提交行为
                
                const caseType = document.getElementById('caseTypeSelect').value;
                const documentFile = document.getElementById('documentUpload').files[0];

                if (!caseType) {
                    alert('请选择案件类型！');
                    return;
                }
                if (!documentFile) {
                    alert('请选择要上传的文档！');
                    return;
                }

                // 在这里可以添加文件上传的逻辑，例如使用 FormData 和 fetch API
                console.log('案件类型:', caseType);
                console.log('上传文档:', documentFile.name, documentFile.size, documentFile.type);
                
                // 实际应用中，上传成功后应更新下面的列表
                alert(`文档 "${documentFile.name}" 已添加 (模拟)。`);
                
                // 清空表单（可选）
                // addKnowledgeForm.reset(); 
            });
        }

        // 列表操作按钮的事件委托示例 (需要更完善的实现)
        const knowledgeTableBody = document.getElementById('knowledgeTableBody');
        if (knowledgeTableBody) {
            knowledgeTableBody.addEventListener('click', function(event) {
                const target = event.target;
                if (target.classList.contains('btn-secondary')) { // 下载按钮
                    const row = target.closest('tr');
                    const docName = row.cells[2].textContent;
                    alert(`准备下载: ${docName} (模拟)`);
                    // 在此添加实际下载逻辑
                } else if (target.classList.contains('btn-danger')) { // 删除按钮
                    const row = target.closest('tr');
                    const docName = row.cells[2].textContent;
                    if (confirm(`确定要删除文档 "${docName}" 吗？`)) {
                        row.remove(); // 从界面移除行 (模拟)
                        alert(`文档 "${docName}" 已删除 (模拟)。`);
                        // 在此添加实际删除逻辑，并更新序号
                    }
                }
            });
        }
    </script>
</body>
</html>